<?php

include ('../session.php');
include ('../db.php');
include ('../functions.php');
include ('config.php');

if ($action == 'add')
{
  print_r ($_POST);

  $c_name = mysql_clean ($name);

  $query = "select location_id
            from " . DKP_LOCATIONS . "
            where location_name = '$c_name'";
  $result = mysql_query ($query);

  $row = mysql_fetch_array ($result);

  if ($row)
  {
  }

  $query = "select idvalue
            from ids
            where idid = " . ID_LOCATION;
  $result = mysql_query ($query);

  $row = mysql_fetch_array ($result);

  $locationid = $row['idvalue'];
  $c_locationid = intval ($locationid);

  $query = "insert into " . DKP_LOCATIONS . "
            (location_id, location_name)
            values ($c_locationid, '$c_name')";
  $result = mysql_query ($query);

  $query = "update ids
            set idvalue = " . intval ($locationid + 1) . "
            where idid = " . ID_LOCATION;
  $result = mysql_query ($query);
}
else if ($action == 'update')
{
}
else if ($action == 'remove')
{
}

$output = '';

$output .= "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
  <head>
    <title>Panic Points - Add Location</title>
    <link href=\"../general.css\" rel=\"stylesheet\" type=\"text/css\">
  </head>
  <body>";

include ('navigation.php');

$output .= "
    <form name=\"locationform\" id=\"locationform\" action=\"addlocation.php\" method=\"POST\">
      <input type=\"hidden\" name=\"action\" id=\"action\" value=\"\">
      <table>
        <tr>
          <td>name</td>
          <td><input type=\"edit\" name=\"name\"></td>
        </tr>
        <tr>
          <td colspan=\"2\">
            <button onclick=\"document.getElementById ('action').value = 'add'; document.getElementById ('locationform').submit ()\">add</button>&nbsp;
            <button onclick=\"document.getElementById ('action').value = 'update'; document.getElementById ('locationform').submit ()\">update</button>&nbsp;
            <button onclick=\"document.getElementById ('action').value = 'remove'; document.getElementById ('locationform').submit ()\">remove</button>
          </td>
        </tr>
      </table>
    </form>";

$output .= "
  </body>
</html>";

echo $output;
